package com.tm.d10_time;

import java.time.LocalTime;
/**
 * 2024/5/24 Cjj LocalTime  15：24
 */
public class Test2_LocalTime {
    public static void main(String[] args) {
        //获取本地对象
        LocalTime now = LocalTime.now();//时 分 秒 纳秒 (不可变的)
        System.out.println(now);

        //1.获取时间中的信息
        int hour = now.getHour();//小时
        int minute = now.getMinute();//分钟
        int second = now.getSecond();//秒
        int nano = now.getNano();//纳秒
        System.out.println(hour);
        System.out.println(minute);
        System.out.println(second);
        System.out.println(nano);

        //2.修改时间
        LocalTime time = now.withHour(3);
        LocalTime withMinute = now.withMinute(3);
        LocalTime withSecond = now.withSecond(3);
        LocalTime withNano = now.withNano(3);
        System.out.println(time);
        System.out.println(withMinute);
        System.out.println(withSecond);
        System.out.println(withNano);

        //3.加多少时间
        LocalTime plusHours = now.plusHours(2);
        LocalTime plusMinutes = now.plusMinutes(2);
        System.out.println(plusMinutes);
        System.out.println(plusHours);

        //4.减多少时间
        LocalTime minusHours = now.minusHours(2);
        LocalTime minusMinutes = now.minusMinutes(2);
        System.out.println(minusMinutes);
        System.out.println(minusHours);

        //5.获取指定日期的LocalDate对象:LocalTime Of
        //public static LocalTime of(int house, int minute int second )
        LocalTime localTime = LocalTime.of(12, 12, 12);
        LocalTime localTime1= LocalTime.of(12, 12, 12);

        //6.判断2个日期对象是否相等,在前还是在后：equals isBefore isAfter
        System.out.println(localTime1.equals(localTime));
        System.out.println(localTime1.isBefore(minusHours));
    }
}
